import request from '@/utils/request'

// 获取资讯列表下拉框用
export function getinformationList(data) {
  return request({
    url: '/banner/getinformationList',
    method: 'post',
    data
  })
}

// 获取商品列表下拉框用
export function getcommodityList(data) {
  return request({
    url: '/banner/getcommodityList',
    method: 'post',
    data
  })
}

// 添加主图
export function bannerAdd(data) {
  return request({
    url: '/banner/bannerAdd',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
      'type': 'upfile'
    },
    data,
    transformRequest: [function(data, headers) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}

// 编辑主图
export function bannerEdit(data) {
  return request({
    url: '/banner/bannerEdit',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data',
      'type': 'upfile'
    },
    data,
    transformRequest: [function(data, headers) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}

// 获取主图列表
export function bannerIndex(data) {
  return request({
    url: '/banner/index',
    method: 'post',
    data
  })
}

// 删除主图
export function delBanner(data) {
  return request({
    url: '/banner/delBanner',
    method: 'post',
    data
  })
}

// 操作上下架状态
export function opBannerStatus(data) {
  return request({
    url: '/banner/opBannerStatus',
    method: 'post',
    data
  })
}

// 顶置主图
export function opBannerSort(data) {
  return request({
    url: '/banner/opBannerSort',
    method: 'post',
    data
  })
}

